package com.cjl.blueBridgeCup.school;

import java.util.ArrayList;
import java.util.Scanner;

public class Practice_1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.nextLine());
        ArrayList<Integer> list = new ArrayList<>();
        int[][] arr = new int[n][2];
        for (int i = 0; i < n; i++) {
            String couple = scan.nextLine();
            String[] split = couple.split(" ");
            arr[i][0] = Integer.parseInt(split[0]);
            arr[i][1] = Integer.parseInt(split[1]);
        }
        int k = Integer.parseInt(scan.nextLine());
        String single = scan.nextLine();
        for (String s : single.split(" ")) {
            list.add(Integer.parseInt(s));
        }
        ArrayList<Integer> singleList = new ArrayList<>();
        for (int s : list) {
            for (int i = 0; i < n; i++) {
                if (arr[i][0] == s && !list.contains(arr[i][1])) {
                    singleList.add(s);
                    break;
                }
                if (arr[i][1] == s && !list.contains(arr[i][0])) {
                    singleList.add(s);
                    break;
                }
            }
        }
        for (Integer s : list) {
            int count = 0;
            for (int i = 0; i < n; i++) {
                if (arr[i][1] != s && arr[i][0] != s) {
                    count++;
                }
            }
            if (count == n) {
                singleList.add(s);
            }
        }
        System.out.println(singleList.size());
        for (int s : singleList) {
            System.out.print(s + " ");
        }
        scan.close();
    }
}